<template>
	<view >
		<view class="mix-product-list" :class="{'is-row': listType === 'row'}">
			<view
				v-if="listType === 'row'"
				v-for="(item, index) in renderList" 
				:key="index"
				class="list-item row b-b"
				@click="navTo('/pages/product/detail?id=' + item.id)"
			>
				<view class="image-wrapper" v-if="item.courseImg">
					<image 
						:src="'https://maxh-1305457127.cos.ap-guangzhou.myqcloud.com/'+item.courseImg" 
						mode="aspectFill" 
						lazy-load="true"
					></image>
				</view>
				<view class="right column">
					<text class="title clamp">{{ item.courseName }}</text>
					<view class="sales">
						 <span class="teacherName">{{ item.username }}</span>
						 <span class="teacherName">{{ item.degree }}</span>
					</view>
					<view class="price-wrap row">
						<mix-price-view :price="item.price" :size="34"></mix-price-view>
						<view class="tags row">
							<view class="tag center">
								<text>{{item.courseType}}</text>
							</view>
						</view>
					</view>
				</view>
				
			</view>
			<view
				v-if="listType === 'column'"
				v-for="item in renderList" 
				:key="item._id"
				class="list-item column"
				@click="navTo('/pages/product/detail?id=' + item.CourseId)"
			>
				<view class="image-wrapper " v-if="item.courseImg">
					<image 
						:src="'https://maxh-1305457127.cos.ap-guangzhou.myqcloud.com/'+item.courseImg" 
						mode="aspectFill" 
						lazy-load="true"
					></image>
				</view>
				<text class="title clamp2">{{ item.courseName }}</text>
				<view class="price-wrap row">
					<mix-price-view :price="item.price"></mix-price-view>
					<view class="fill"></view>
				</view>
			</view>
		</view>
		<view v-if="renderList.length===0" class="image-bg ">
			<view class="center">
				<image src="../../../static/icon/default-avatar.png" class="img-png"></image>
			</view>
			<view class="img-text">空空如也</view>
		</view>
	</view>
	
</template>

<script>
	export default {
		name: 'MixProductList',
		data() {
			return {
				loadType: 'add',//标记加载还是刷新数据
				renderList: []
			};
		},
		props: {
			list: {
				type: Array,
				default(){
					return []
				}
			},
			listType: {
				type: String,
				default: 'column'
			}
		},
		watch: {
			list(list){
				// console.log(list);
				this.renderList = list;
			}
		},
		methods: {
			
		}
	}
</script>

<style scoped lang="scss">
	.mix-product-list{
		display:flex;
		justify-content: space-between;
		flex-wrap:wrap;
		width: 710rpx;
		margin-left: 20rpx;
		background-color: #f7f7f7;
		
		&.is-row{
			margin-top: -4rpx;
			border-radius: 8rpx;
			box-shadow: 4rpx 4rpx 20rpx rgba(0,0,0,.06);
			overflow: hidden;
		}
	}
	/* 横向列表 */
	.list-item.row{
		width: 100%;
		padding: 24rpx 0 24rpx 24rpx;
		background-color: #fff;
		
		&:after{
			border-color: #eaeaea;
			left: 6rpx;
			right: 6rpx;
		}
		&:last-child:after{
			border: 0;
		}
		.image-wrapper{
			flex-shrink: 0;
			width: 160rpx;
			height: 160rpx;
			margin-right: 20rpx;
			border-radius: 6rpx;
			overflow: hidden;
			
			image{
				width: 100%;
				height: 100%;
			}
		}
		.right{
			flex: 1;
			overflow: hidden;
		}
		.title{
			margin-right: 24rpx;
			font-size: 30rpx;
			color: #333;
			line-height: 40rpx;
		}
		.sales{
			height: 40rpx;
			margin: 14rpx 0 28rpx;
			line-height: 40rpx;
			font-size: 26rpx;
			color: #888;
		}
		.price-wrap{
			display: flex;
			align-items: baseline;
			padding-right: 20rpx;
		}
		.m-price{
			font-size: 26rpx;
			text-decoration: line-through;
			color: #999;
			margin-left: 10rpx;
		}
		.tags{
			flex: 1;
			justify-content: flex-end;
			position: relative;
			bottom: 4rpx;
		}
		.tag{
			height: 32rpx;
			padding: 0 10rpx;
			margin-left: 10rpx;
			font-size: 20rpx;
			color: #fff;
			border-radius: 4rpx;
			background-color: $base-color;
			
			&.orange{
				background-color: orange;
			}
		}
	}
	/* 竖向列表 */
	.list-item.column{
		width: 350rpx;
		padding-bottom: 16rpx;
		margin-bottom: 12rpx;
		background: #fff;
		border-radius: 8rpx;
		overflow: hidden;
		box-shadow: 0 0 16rpx rgba(0,0,0,.06);
		position: relative;
		
		.image-wrapper{
			width: 100%;
			height: 350rpx;
			overflow: hidden;
			
			image{
				width: 100%;
				height: 100%;
			}
		}
		.title{
			font-size: 28rpx;
			color: #333;
			line-height: 36rpx;
			padding: 0 16rpx;
			margin-top: 18rpx;
			height: 76rpx;
		}
		.price-wrap{
			padding: 0 16rpx;
			margin-top: 18rpx;
		}
		.m-price{
			font-size: 24rpx;
			text-decoration: line-through;
			color: #999;
			margin-left: 10rpx;
			
			&:before{
				content: "￥";
			}
		}
		.tag{
			height: 32rpx;
			padding: 0 10rpx;
			font-size: 20rpx;
			background-color: $base-color;
			color: #fff;
			border-radius: 4rpx;
			transform: translateY(-4rpx);
		}
	}
	.teacherName{
		background-color: #e5e5e5;
		color: #969696;
		margin-right:15rpx;
		font-size: 16rpx;
	}
	.image-bg{

		text-align: center;
		border-radius: 6rpx;
		.img-text{
			font-size: 16rpx;
			color: #82939C;
		}
	}
	.img-png{
		text-align: center;
		width: 160rpx;
		height: 160rpx;
	}
</style>
